/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GestionPlanning.java
 *
 * Created on 1 juin 2011, 14:45:32
 */

package cannes.gui;

import cannes.bean.planning.Film;
import cannes.bean.planning.Planning;
import cannes.bean.planning.Projection;
import cannes.dao.DAO;
import cannes.dao.DAOFactory;
import cannes.dao.implement.PlanningDAO;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Set;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author p1008977
 */
public class GestionPlanning extends javax.swing.JPanel {

    /** Creates new form GestionPlanning */
    public GestionPlanning() {
        initComponents();
        //compteurs pour placer ligne après ligne dans le tableau
        int iLundi, iMardi, iMercredi, iJeudi, iVendredi, iSamedi, iDimanche;
        iLundi = iMardi = iMercredi = iJeudi = iVendredi = iSamedi = iDimanche = 0;
        String[] columnNames = {"Dimanche",
                        "Lundi",
                        "Mardi",
                        "Mercredi",
                        "Jeudi",
                        "Vendredi",
                        "Samedi"};
        
        Object[][] planningTab = new Object[7][8];
        DAO<Planning> planningDAO = DAOFactory.getPlanningDAO();
        DAO<Film> filmDAO = DAOFactory.getFilmDAO();
        //TODO: vérifier que 2 correspond bien à la catégorie voulue
        Planning planning = planningDAO.find(2);
        Set<Projection>  liste = planning.getListeProjection();
        for (Projection projection : liste) {
            
            Calendar c = Calendar.getInstance();
            c.setFirstDayOfWeek(Calendar.MONDAY);
            c.setTime(projection.getHorraire());
            int jour = c.get(Calendar.DAY_OF_WEEK);
            
            //TODO: refaire ça en plus propre, et faire les autres onglets pour les autres catégories
            switch(jour){
                case Calendar.MONDAY:
                    //Calendar.SUNDAY est 1, si on veut que sunday soit 0, il faut jour-1
                    planningTab[iLundi++][jour-1] =filmDAO.find(projection.getFilm()).getTitre()+
                        ", " + c.getTime();
                case Calendar.TUESDAY:
                    planningTab[iMardi++][jour-1] =filmDAO.find(projection.getFilm()).getTitre()+
                        ", " + c.getTime();    
                case Calendar.WEDNESDAY:
                    planningTab[iMercredi++][jour-1] =filmDAO.find(projection.getFilm()).getTitre()+
                        ", " + c.getTime();
                case Calendar.THURSDAY:
                    planningTab[iJeudi++][jour-1] =filmDAO.find(projection.getFilm()).getTitre()+
                        ", " + c.getTime();
                case Calendar.FRIDAY:
                    planningTab[iVendredi++][jour-1] =filmDAO.find(projection.getFilm()).getTitre()+
                        ", " + c.getTime();
                case Calendar.SATURDAY:
                    planningTab[iSamedi++][jour-1] =filmDAO.find(projection.getFilm()).getTitre()+
                        ", " + c.getTime();
                case Calendar.SUNDAY:
                    planningTab[iDimanche++][jour-1] =filmDAO.find(projection.getFilm()).getTitre()+
                        ", " + c.getTime();
                    break;
            }
        }
        
        DefaultTableModel tableModel = new DefaultTableModel(planningTab, columnNames);
        this.tablePlanning.setModel(tableModel);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonNouveau = new javax.swing.JButton();
        buttonSupprimer = new javax.swing.JButton();
        buttonDeplacer = new javax.swing.JButton();
        tabbedPanePlannings = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePlanning = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();

        buttonNouveau.setText("Nouveau");
        buttonNouveau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNouveauActionPerformed(evt);
            }
        });

        buttonSupprimer.setText("Supprimer");
        buttonSupprimer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSupprimerActionPerformed(evt);
            }
        });

        buttonDeplacer.setText("Déplacer");

        jScrollPane1.setViewportView(tablePlanning);

        tabbedPanePlannings.addTab("LM", jScrollPane1);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"9h Le Tonneau Salle Debussy", null, "10h La Vengeance de johnny", null, null, null},
                {null, null, "14h Retour en Ouzaganda", null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "lundi", "mardi", "jeudi", "vendredi", "samedi", "dimanche"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        tabbedPanePlannings.addTab("CM", jScrollPane2);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable2);

        tabbedPanePlannings.addTab("HC", jScrollPane3);

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane4.setViewportView(jTable3);

        tabbedPanePlannings.addTab("URC", jScrollPane4);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(buttonNouveau)
                        .addGap(18, 18, 18)
                        .addComponent(buttonSupprimer)
                        .addGap(18, 18, 18)
                        .addComponent(buttonDeplacer))
                    .addComponent(tabbedPanePlannings, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonNouveau)
                    .addComponent(buttonSupprimer)
                    .addComponent(buttonDeplacer))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPanePlannings, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void buttonSupprimerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSupprimerActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_buttonSupprimerActionPerformed

    private void buttonNouveauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNouveauActionPerformed
        NouvelleProjection np = new NouvelleProjection();
        np.setVisible(true);
        JFrame f = new JFrame("Nouvelle Projection");
        f.add(np);
        f.setSize(800, 500);
        f.setVisible(true);
    }//GEN-LAST:event_buttonNouveauActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonDeplacer;
    private javax.swing.JButton buttonNouveau;
    private javax.swing.JButton buttonSupprimer;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTabbedPane tabbedPanePlannings;
    private javax.swing.JTable tablePlanning;
    // End of variables declaration//GEN-END:variables

}
